package com.szrt.zw.test.base;


import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.szrt.zw.test.student.entity.StudentEntity;



public abstract class BaseServiceImpl<T> implements BaseService<T> {
	
	
	// 访问数据库
	public abstract BaseDao<T> getBaseDao();
	
	
	/**
	 * 增加
	 */
	
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	@Override
	public int add(T entity) {
		return getBaseDao().insert(entity);
	}

	/**
	 * 硬删除
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	@Override
	public int deleteById(Integer id) {
		return getBaseDao().deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	@Override
	public int deleteByIds(List<Integer> ids) {
		return getBaseDao().deleteByIds(ids);
	}

	/**
	 * 修改
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	@Override
	public int update(T entity) {
		return getBaseDao().updateByPrimaryKey(entity);
	}

	/**
	 * 查询
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public T findById(Integer id) {
		return getBaseDao().selectByPrimaryKey(id);
	}
	@Override
	public List<StudentEntity> findAll(Map<String, Object> pageMap){
		return getBaseDao().findAll(pageMap);
	}
	public int getTotalCounter(Map<String, Object> pageMap){
		return getBaseDao().getTotalCounter(pageMap);
	}
}
